<template>
  <div class="app-loading">
    <div class="loading-container">
      <!-- Logo区域 -->
      <div class="logo-section">
        <div class="logo">
          <img src="@/assets/logo.png" alt="Logo" class="logo-image" />
        </div>
        <h1 class="app-title">星遇校园</h1>
      </div>

      <!-- 加载动画 -->
      <div class="loading-section">
        <div class="loading-spinner">
          <div class="spinner"></div>
        </div>
        <p class="loading-text">{{ loadingText }}</p>

        <!-- 进度条 -->
        <div class="progress-bar">
          <div class="progress-fill" :style="{ width: `${progress}%` }"></div>
        </div>

        <!-- 状态提示 -->
        <div class="status-text">{{ statusText }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'

interface Props {
  loadingText?: string
  statusText?: string
  progress?: number
}

const props = withDefaults(defineProps<Props>(), {
  loadingText: '正在初始化应用...',
  statusText: '加载中，请稍候',
  progress: 0,
})

// 动态更新进度条
const progress = ref(props.progress)

onMounted(() => {
  // 模拟进度更新
  const interval = setInterval(() => {
    if (progress.value < 90) {
      progress.value += Math.random() * 10
    }
  }, 200)

  // 清理定时器
  setTimeout(() => {
    clearInterval(interval)
  }, 3000)
})
</script>

<style scoped>
.app-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('@/assets/bg1.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-container {
  text-align: center;
  color: white;
  max-width: 400px;
  padding: 2rem;
}

.logo-section {
  margin-bottom: 3rem;
}

.logo {
  margin-bottom: 1rem;
}

.logo-image {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.app-title {
  font-size: 2rem;
  font-weight: 600;
  margin: 0;
  margin-top: 1rem;
  color: white;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.loading-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.loading-spinner {
  position: relative;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 1.2rem;
  font-weight: 500;
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  border-radius: 2px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.status-text {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
  min-height: 1.2rem;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .loading-container {
    padding: 1rem;
    max-width: 320px;
  }

  .app-title {
    font-size: 1.5rem;
  }

  .loading-text {
    font-size: 1rem;
  }

  .logo-image {
    width: 48px;
    height: 48px;
  }
}
</style> 